package com.mty.springboot.service.impl;

import com.mty.springboot.dao.ScoreMapper;
import com.mty.springboot.model.PageInfo;
import com.mty.springboot.model.Score;
import com.mty.springboot.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import com.mty.springboot.util.*;

/**
 * 用户Service接口实现类
 * @author: mty
 */
@Service("scoreService")
@Transactional
public class ScoreServiceImpl implements ScoreService {

    @Autowired
    private ScoreMapper scoreMapper;


    //分页查询
    @Override
    public PageInfo<Score> findPageInfo(Integer pageIndex, Integer pageSize, Map mp) {
        PageInfo<Score> pi = new PageInfo<Score>();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        mp.put("currentPage",(pi.getPageIndex()-1)*pi.getPageSize());
        mp.put("pageSize",pi.getPageSize());
        //获取总条数
        Integer totalCount = scoreMapper.totalCount(mp);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //按条件查询
            List<Score> scoreList =	scoreMapper.getScoreList(mp);
            pi.setList(scoreList);
        }
        return pi;
    }


    //添加
    @Override
    public int addScore(Score score) {
        score.setId(uuid.getRandomIdByUUID());
        return scoreMapper.addScore(score);
    }


    //根据id删除
    @Override
    public int deleteScore(String id) {
        return scoreMapper.deleteScore(id);
    }


    //修改宿舍信息
    @Override
    public int updateScore(Score score) {
        return scoreMapper.updateScore(score);
    }

    //根据ID查询
    @Override
    public Score findScoreById (String id){
        Score d = scoreMapper.findScoreById(id);
        return  d;
    }

    //查询所有
    @Override
    public List<Score> getAll(){
        List<Score> scoreList = scoreMapper.getAll();
        return scoreList;
    }

    //按照条件查询
    @Override
    public List<Score> queryFilter(Map mp){
        List<Score> scoreList = scoreMapper.queryFilter(mp);
        return scoreList;
    }

    //获取积分榜
    @Override
    public List<Score> queryBang(){
        List<Score> scoreList = scoreMapper.queryBang();
        return scoreList;
    }
}
